﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using FlowBasis.Web.Security;
using FlowBasis.Security.Principal;

namespace FlowBasisSampleSite.Lib.Security
{
    public class FormsAuthenticationService : IFormsAuthenticationService
    {
        public void SignIn(string userToken, bool createPersistentCookie)
        {
            FormsAuthentication.SetAuthCookie(userToken, createPersistentCookie);
        }

        public void SignOut()
        {
            var httpContext = HttpContext.Current;
            if (httpContext != null)
            {
                var principalWithSignOutHandler = httpContext.User as IPrincipalWithSignOutHandler;
                if (principalWithSignOutHandler != null)
                {
                    principalWithSignOutHandler.HandleSignOut();
                }
            }

            FormsAuthentication.SignOut();
        }
    }
}